class Solution:
    def isValid(self, s: str) -> bool:
        if len(s)%2 != 0:
            return False
        a=[]
        dic = {")":"(", "}":"{", "]":"["}
        for i in range(len(s)):
            b=s[i]
            if s[i] in "([{":
                a.append(b)
            elif len(a)>0 and dic.get(s[i]) == a[-1]:
                a.pop()
            else:
                return False
        return not a